(function(){
	wlxer = {
		init:function(){
			var self = this;
			//清除
			self.clearInput();
		},
		clearInput:function(){
			var again = false;

			//输入内容显示『X』	
			$('.step input').on('keyup focus',function(){
				var $this = $(this),
					$clear = $this.next('.weui-icon-clear'),
					phone = $this.val();
				
				$('.weui-icon-clear').addClass('f-dn');
				if ( phone!='' ){
					$clear.removeClass('f-dn');
				} else {
					$clear.addClass('f-dn');
				}

			});

			//清除输入的内容
			$('.weui-icon-clear').on('click',function(){
				var $this = $(this),
					$input = $this.prev();
				$input.val('');
				$this.addClass('f-dn');
			});

			//获取验证码，倒计时
			$('.veriCode').on('click',function(){
				var $this = $(this),
					second = 60,
					con = '<span>正在获取</span><em>'+ second +'</em>',
					$con = $.parseHTML(con),
					timer = null;

				//正在倒计时，则返回;
				if (again) return;

				again = true;

				$this.html($con);

				timer = setInterval(function(){
					second--;
					if (second==0) {
						clearInterval(timer);
						$this.html('<span>重新获取</span>');
						again = false;
					}
					$($con[1]).text(second);
				},1000)

			});

			//判断手机号是否正确
			$('.weui-cell__ft').on('click',function(){
				var phone = $('.tel').val().trim();

				//正则判断手机号
				if(phone!='' && !(/^1[34578]\d{9}$/.test(phone))){ 
					$.toast.prototype.defaults.duration = 1500;
			        $.toast('手机格式不正确','cancel');
			        return false;
			    } else if(phone==''){
			    	return false;
			    }

			});
		}
	}
})()

$(function(){
	wlxer.init();
});